package net.zdreamer.shunyi.ui.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import net.zdreamer.shunyi.R;

public class PanhangActivity extends FragmentActivity implements View.OnClickListener {
    private RelativeLayout title;
    private ImageView back;
    private TextView titlecontent;
    private LinearLayout banghui, gongxian, banghuibuttom, gongxianbuttom;
    private boolean ischoose = true;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_panhang);
        title = (RelativeLayout) findViewById(R.id.title_item);
        titlecontent = (TextView) findViewById(R.id.title_content);
        back = (ImageView) findViewById(R.id.leftimg);
        title.setBackgroundResource(R.drawable.newsbiaoti);
        titlecontent.setText("排行榜");
        titlecontent.setTextColor(getResources().getColor(R.color.white));
        back.setImageResource(R.drawable.backimg);
        back.setOnClickListener(this);

        banghui = (LinearLayout) findViewById(R.id.paihang_banghui);
        banghuibuttom = (LinearLayout) findViewById(R.id.paihang_banghuibottom);

        gongxian = (LinearLayout) findViewById(R.id.paihang_gongxian);
        gongxianbuttom = (LinearLayout) findViewById(R.id.gongxian_paihang);
        banghui.setOnClickListener(this);
        gongxian.setOnClickListener(this);

        addfragment(new BanghuiPaihangFragment());
    }

    public void addfragment(Fragment fragment) {
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        ft.replace(R.id.paihang_fragment, fragment);
        ft.commit();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.paihang_banghui:
                addfragment(new BanghuiPaihangFragment());
                ischoose = false;
                showBottom();
                break;
            case R.id.paihang_gongxian:
                ischoose = true;
                addfragment(new PaihangFragment());
                showBottom();
                break;
            case R.id.leftimg:
                this.finish();
                break;
            default:
                break;
        }
    }
    public void showBottom() {
        if (!ischoose) {
            banghuibuttom.setVisibility(View.VISIBLE);
            gongxianbuttom.setVisibility(View.INVISIBLE);
        } else {
            banghuibuttom.setVisibility(View.INVISIBLE);
            gongxianbuttom.setVisibility(View.VISIBLE);
        }
    }
}
